﻿#region

using System.Security.Cryptography;
using System.Text;

#endregion

namespace Vin.Tool.Core.EncryptCategory;

public class Md5EncryptTool
{
    /// <summary>
    /// MD5加密
    /// </summary>
    /// <param name="str">待加密字符串</param>
    /// <returns></returns>
    public static string Md5Encrypt(string str)
    {
        var result = BitConverter.ToString(MD5.HashData(Encoding.UTF8.GetBytes(str)));
        return result.Replace("-", "").ToLower();
    }

    /// <summary>
    /// MD5加密 指定次数
    /// </summary>
    /// <param name="str"></param>
    /// <param name="num"></param>
    /// <returns></returns>
    public static string Md5EncryptByNum(string str, int num = 3)
    {
        var result = Md5Encrypt(str);
        for (int i = 0; i < num - 1; i++)
        {
            result = Md5Encrypt(result);
        }

        return result;
    }
}